package com.woniu.smallmedical.controller;

import com.woniu.smallmedical.entity.*;
import com.woniu.smallmedical.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author author
 * @create 2021-10-08-18:54
 */
@RestController
public class MedicalRecordController {
    @Autowired
    PrescriptionMapper prescriptionMapper;

    @Autowired
    PrescriptionDetailsMapper prescriptionDetailsMapper;

    @Autowired
    RegistrationMapper registrationMapper;

    @Autowired
    MedicalRecordMapper medicalRecordMapper;

    @Autowired
    PhysiqueMapper physiqueMapper;

    @GetMapping("/saveMedicalRecord")
    public ResponseResult saveMedicalRecord(MedicalRecord medicalRecord, Physique physique) {
        // 用户id
        Integer paid = Integer.valueOf(physique.getPatientinformation());

        // 查询处方表id
        Registration bySickid = registrationMapper.getBySickid(paid);

        // 处方
        Prescription byRid = prescriptionMapper.getByRid(bySickid.getRid());

        // 处方详细
        PrescriptionDetails byPrid = prescriptionDetailsMapper.getByPrid(byRid.getPrid());

        physiqueMapper.insert(physique.getHeat(),
                physique.getBreathe(),
                physique.getPulse(),
                physique.getBlood(),
                physique.getHeight(),
                physique.getWeight(),
                physique.getGlucose(),
                physique.getFat(),
                physique.getPatientinformation());

        medicalRecordMapper.insert(medicalRecord.getOnsetdate(),
                medicalRecord.getComplaint(),
                medicalRecord.getPresenthistory(),
                medicalRecord.getPastillnesshistory(),
                medicalRecord.getAllergichistory(),
                medicalRecord.getPersonalhistory(),
                medicalRecord.getFamilyhistory(),
                medicalRecord.getExamination(),
                medicalRecord.getTreatment(),
                medicalRecord.getRemarks(),
                byRid.getPrid(),
                physiqueMapper.getPhysiqueByPaid(physique.getPatientinformation()).getPid());

        return new ResponseResult(null, 200, "");
    }


}
